package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.BlackListApi;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.pojo.BlackList;
import com.tanhua.dubbo.vo.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService(version = "1.0.0")
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageInfo<BlackList> queryBlackList(Long userId, Integer page, Integer pageSize) {
        PageInfo<BlackList> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page);
        pageInfo.setPageSize(pageSize);

        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        List<BlackList> blackList = this.blackListMapper.selectList(queryWrapper);
        pageInfo.setRecords(blackList);
        return pageInfo;
    }

    @Override
    public Integer queryBlackListCount(Long userId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        Integer count = this.blackListMapper.selectCount(queryWrapper);
        return count;
    }

    @Override
    public Boolean deleteBlackUser(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.eq("black_user_id", blackUserId);
        int count = this.blackListMapper.delete(wrapper);
        return count > 0;
    }
}
